import { defineComponent, ref } from 'vue'
import { useRoute } from 'vue-router'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import request from '@/request'


export default defineComponent({
  name: "userBlog",
  components: { Editor, Toolbar },
  setup: function () {
    const route = useRoute()
    const bId = route.params.bId // 获取当前博客ID
    const editorId = 'TangEditor-2'//编辑器id
    const editorConfig = { readOnly: true}// 只读模式

    // 博客数据内容
    const blogData = ref({
      bId: '',
      bTitle: '',
      bSTitle: '',
      bContent: '',
      bCover: '',
      remark:'',
      status:'',
      bLike:'',
      bWatch:'',
      createTime:'',
      updateTime:'',
      delFlag:'',
      tags:[{
        tName:'1',
        status:'0',
        remark:'1',
        tId:'1',
        createTime:'',
        updateTime:'',
        delFlag:''
      }]
    })
    const getDefaultContent = ref([])// 博客内容
    const userBlogTitle = ref('')

    const isEditorShow = ref(false)
    // 根据ID获取博客数据
    const getBlogData = () => {
      request('/api/blogs/getById', 'get', { bId: bId }).then(
        (res) => {
          isEditorShow.value = true
          blogData.value = res.data
          getDefaultContent.value = eval(blogData.value.bContent)
          userBlogTitle.value =blogData.value.bTitle
        },
      )
    }
    return {
      editorId,
      editorConfig,
      userBlogTitle,
      getDefaultContent,
      mode: 'default',
      getBlogData,
      isEditorShow,

    }
  },
  created() {
    this.getBlogData()
  },
})
